#!/usr/bin/env node

const axios = require('axios'),
      qs = require('querystring'),
      url = 'http://www.dm5.com/dm5.ashx?t=1594800248240',
      fs = require('fs'),
      path = require('path')
      //url = 'http://localhost:8080/',
      body = {
        pagesize: 68,
        pageindex: 1,
        tagid :0,
        areaid: 0,
        status:0,
        usergroup: 0,
        pay: -1,
        char: '',
        sort: 10,
        action: 'getclasscomics'
      },
      total = 3 

var res,data,fileName

async function getPage(page){
  body.pageindex = page
  res = await axios.post(url, qs.stringify(body))
  return res.data

 // console.log(res);

}
async function getAllData(page){
  for(var page = 1;page <= total ; page++){
    data = await getPage(page)
      console.log(data)
      fileName = path.join(__dirname, 'data', page + '.json')
      fs.writeFileSync(fileName, JSON.stringify(data))
  }
}

getAllData()




